(function(b, a) {
  typeof exports === "object" && typeof module !== "undefined" ? module.exports = a(b) : typeof define === "function" && define.amd ? define(a) : a(b)
})(typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : this, function(r) {
  var j = r.Base64;
  var e = "2.4.5";
  var s;
  if (typeof module !== "undefined" && module.exports) {
    try {
      s = require("buffer").Buffer
    } catch (g) {}
  }
  var p = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var c = function(C) {
    var B = {};
    for (var A = 0, z = C.length; A < z; A++) {
      B[C.charAt(A)] = A
    }
    return B
  }(p);
  var v = String.fromCharCode;
  var x = function(A) {
    if (A.length < 2) {
      var z = A.charCodeAt(0);
      return z < 128 ? A : z < 2048 ? v(192 | z >>> 6) + v(128 | z & 63) : v(224 | z >>> 12 & 15) + v(128 | z >>> 6 & 63) + v(128 | z & 63)
    } else {
      var z = 65536 + (A.charCodeAt(0) - 55296) * 1024 + (A.charCodeAt(1) - 56320);
      return v(240 | z >>> 18 & 7) + v(128 | z >>> 12 & 63) + v(128 | z >>> 6 & 63) + v(128 | z & 63)
    }
  };
  var k = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
  var h = function(z) {
    return z.replace(k, x)
  };
  var q = function(C) {
    var B = [0, 2, 1][C.length % 3],
      z = C.charCodeAt(0) << 16 | (C.length > 1 ? C.charCodeAt(1) : 0) << 8 | (C.length > 2 ? C.charCodeAt(2) : 0),
      A = [p.charAt(z >>> 18), p.charAt(z >>> 12 & 63), B >= 2 ? "=" : p.charAt(z >>> 6 & 63), B >= 1 ? "=" : p.charAt(z & 63)];
    return A.join("")
  };
  var l = r.btoa ? function(z) {
    return r.btoa(z)
  } : function(z) {
    return z.replace(/[\s\S]{1,3}/g, q)
  };
  var o = s ? s.from && Uint8Array && s.from !== Uint8Array.from ? function(z) {
    return (z.constructor === s.constructor ? z : s.from(z)).toString("base64")
  } : function(z) {
    return (z.constructor === s.constructor ? z : new s(z)).toString("base64")
  } : function(z) {
    return l(h(z))
  };
  var f = function(z, A) {
    return !A ? o(String(z)) : o(String(z)).replace(/[+\/]/g, function(B) {
      return B == "+" ? "-" : "_"
    }).replace(/=/g, "")
  };
  var u = function(z) {
    return f(z, true)
  };
  var d = new RegExp(["[À-ß][-¿]", "[à-ï][-¿]{2}", "[ð-÷][-¿]{3}"].join("|"), "g");
  var t = function(B) {
    switch (B.length) {
      case 4:
        var z = (7 & B.charCodeAt(0)) << 18 | (63 & B.charCodeAt(1)) << 12 | (63 & B.charCodeAt(2)) << 6 | 63 & B.charCodeAt(3),
          A = z - 65536;
        return v((A >>> 10) + 55296) + v((A & 1023) + 56320);
      case 3:
        return v((15 & B.charCodeAt(0)) << 12 | (63 & B.charCodeAt(1)) << 6 | 63 & B.charCodeAt(2));
      default:
        return v((31 & B.charCodeAt(0)) << 6 | 63 & B.charCodeAt(1))
    }
  };
  var b = function(z) {
    return z.replace(d, t)
  };
  var a = function(D) {
    var z = D.length,
      B = z % 4,
      C = (z > 0 ? c[D.charAt(0)] << 18 : 0) | (z > 1 ? c[D.charAt(1)] << 12 : 0) | (z > 2 ? c[D.charAt(2)] << 6 : 0) | (z > 3 ? c[D.charAt(3)] : 0),
      A = [v(C >>> 16), v(C >>> 8 & 255), v(C & 255)];
    A.length -= [0, 0, 2, 1][B];
    return A.join("")
  };
  var i = r.atob ? function(z) {
    return r.atob(z)
  } : function(z) {
    return z.replace(/[\s\S]{1,4}/g, a)
  };
  var w = s ? s.from && Uint8Array && s.from !== Uint8Array.from ? function(z) {
    return (z.constructor === s.constructor ? z : s.from(z, "base64")).toString()
  } : function(z) {
    return (z.constructor === s.constructor ? z : new s(z, "base64")).toString()
  } : function(z) {
    return b(i(z))
  };
  var m = function(z) {
    return w(String(z).replace(/[-_]/g, function(A) {
      return A == "-" ? "+" : "/"
    }).replace(/[^A-Za-z0-9\+\/]/g, ""))
  };
  var y = function() {
    var z = r.Base64;
    r.Base64 = j;
    return z
  };
  r.Base64 = {
    VERSION: e,
    atob: i,
    btoa: l,
    fromBase64: m,
    toBase64: f,
    utob: h,
    encode: f,
    encodeURI: u,
    btou: b,
    decode: m,
    noConflict: y
  };
  if (typeof Object.defineProperty === "function") {
    var n = function(z) {
      return {
        value: z,
        enumerable: false,
        writable: true,
        configurable: true
      }
    };
    r.Base64.extendString = function() {
      Object.defineProperty(String.prototype, "fromBase64", n(function() {
        return m(this)
      }));
      Object.defineProperty(String.prototype, "toBase64", n(function(z) {
        return f(this, z)
      }));
      Object.defineProperty(String.prototype, "toBase64URI", n(function() {
        return f(this, true)
      }))
    }
  }
  if (r.Meteor) {
    Base64 = r.Base64
  }
  if (typeof module !== "undefined" && module.exports) {
    module.exports.Base64 = r.Base64
  } else {
    if (typeof define === "function" && define.amd) {
      define([], function() {
        return r.Base64
      })
    }
  }
  return {
    Base64: r.Base64
  }
});
if (typeof(Storage) !== "undefined") {
  Storage.prototype.setObject = function(a, b) {
    this.setItem(a, JSON.stringify(b))
  };
  Storage.prototype.getObject = function(a) {
    var b = this.getItem(a);
    return b && JSON.parse(b)
  }
}
Array.prototype.contains = function(b) {
  var a = this.length;
  while (a--) {
    if (this[a] === b) {
      return true
    }
  }
  return false
};
jQuery.support.cors = true;
var shortUrlArr = ["url", "t", "dwz", "suo"],
  service1Arr = ["tiktokv", "tiktokcdn", "tiktok", "musical", "flipagram"],
  hostMap = {
    huoshan: "huoshan.iiilab.com",
    huoshanzhibo: "huoshan.iiilab.com",
    hotsoonzb: "huoshan.iiilab.com",
    smzhuhe: "huoshan.iiilab.com",
    woaidazhe: "huoshan.iiilab.com",
    gifshow: "kuaishou.iiilab.com",
    kuaishou: "kuaishou.iiilab.com",
    kwai: "kuaishou.iiilab.com",
    kw: "kuaishou.iiilab.com",
    yxixy: "kuaishou.iiilab.com",
    chenzhongtech: "kuaishou.iiilab.com",
    miaopai: "weibo.iiilab.com",
    xiaokaxiu: "weibo.iiilab.com",
    yixia: "weibo.iiilab.com",
    weibo: "weibo.iiilab.com",
    weico: "weibo.iiilab.com",
    toutiao: "toutiao.iiilab.com",
    "365yg": "toutiao.iiilab.com",
    ixigua: "toutiao.iiilab.com",
    xiguaapp: "toutiao.iiilab.com",
    xiguavideo: "toutiao.iiilab.com",
    xiguashipin: "toutiao.iiilab.com",
    pstatp: "toutiao.iiilab.com",
    zijiecdn: "toutiao.iiilab.com",
    zijieimg: "toutiao.iiilab.com",
    toutiaocdn: "toutiao.iiilab.com",
    toutiaoimg: "toutiao.iiilab.com",
    toutiao12: "toutiao.iiilab.com",
    toutiao11: "toutiao.iiilab.com",
    neihanshequ: "toutiao.iiilab.com",
    meipai: "meipai.iiilab.com",
    tiktokv: "douyin.iiilab.com",
    tiktokcdn: "douyin.iiilab.com",
    tiktok: "douyin.iiilab.com",
    douyin: "douyin.iiilab.com",
    iesdouyin: "douyin.iiilab.com",
    amemv: "douyin.iiilab.com",
    douyinshortvideo: "douyin.iiilab.com",
    dyshortvideo: "douyin.iiilab.com",
    musical: "muse.iiilab.com",
    musemuse: "muse.iiilab.com",
    muscdn: "muse.iiilab.com",
    xiaoying: "xiaoying.iiilab.com",
    vivavideo: "xiaoying.iiilab.com",
    immomo: "momo.iiilab.com",
    momocdn: "momo.iiilab.com",
    inke: "inke.iiilab.com",
    flipagram: "flipagram.iiilab.com",
    "163": "yunyinyue.iiilab.com",
    hulushequ: "pipixia.iiilab.com",
    "weishi.qq": "weishi.iiilab.com",
    "qzone.qq": "weishi.iiilab.com",
    "kg3.qq": "kg.iiilab.com",
    "kg.qq": "kg.iiilab.com"
  };

function parseHost(a) {
  var c = document.createElement("a");
  c.href = a;
  var b = c.hostname.split(".");
  if (b.length < 2) {
    return ""
  }
  return b[b.length - 2]
}

function parseSubHost(a) {
  var c = document.createElement("a");
  c.href = a;
  var b = c.hostname.split(".");
  if (b.length < 3) {
    return ""
  }
  return b[b.length - 3] + "." + b[b.length - 2]
}

function parseSuffix(a) {
  var b = document.createElement("a");
  b.href = a;
  return b.pathname.split(".").pop()
}

function isMP4File(a) {
  var b = parseSuffix(a);
  return b.toUpperCase() === "MP4"
}

function isIE() {
  var a = window.navigator.userAgent;
  return a.indexOf("MSIE ") > 0 || a.indexOf("Trident/") > 0
}

function detectIE() {
  if (isIE()) {
    $("#app .row .col-md-12").prepend('<div style="text-align: center;" class="alert alert-danger" role="alert">发现您正在使用IE内核浏览器，部分功能可能无法正常使用，建议使用WebKit内核浏览器访问本站获得最佳上网体验。<a target="_blank" href="http://www.jianshu.com/p/a70521aba2b3">详情>></a></div>')
  }
}
var app = new Vue({
  el: "#app",
  data: {
    link: "",
    linkFromInit: false,
    submitBtnClass: {
      disabled: false
    },
    errorTip: "",
    isMP4File: false,
    requestSuccess: false,
    showAllSupportLink: false,
    showClearBtn: false,
    requestResult: {
      video: "",
      text: "",
      cover: "",
      videoType: ""
    },
    sponsor: {
      text: [],
      img: []
    },
    gaCode: '<ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-2341115656300335" data-ad-slot="2960734406" data-ad-format="horizontal"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script>'
  },
  watch: {
    link: function(b, a) {
      if (b.length > 0) {
        this.showClearBtn = true;
        $(".input-group-lg .link-input").css("padding-right", "32px")
      } else {
        this.showClearBtn = false;
        $(".input-group-lg .link-input").css("padding-right", "16px")
      }
    }
  },
  methods: {
    gaga: function(a, b) {
      ga("send", "event", a, a + "-" + (b + 1))
    },
    videoDownloadLink: function(a, b) {
      if (typeof(b) === "undefined") {
        b = "video"
      }
      return "http://service0.iiilab.com/video/iiilab/" + b + "_iiilab_" + new Date().getTime() + Math.random().toString(10).substring(2, 4) + ".mp4?source=" + Base64.encode(a)
    },
    toggleAllSupportLink: function() {
      this.showAllSupportLink = !this.showAllSupportLink
    },
    submit: function(b) {
      if (this.submitBtnClass.disabled) {
        return
      }
      this.removeLastResult();
      if (this.link == "") {
        this.errorTip = "请先将视频链接粘贴到上面的输入框";
        return
      }
      var d = this.link.lastIndexOf("http://");
      d = (d === -1) ? this.link.lastIndexOf("https://") : d;
      if (d === -1) {
        this.errorTip = "请输入正确的视频链接";
        return
      }
      this.link = this.link.substr(d);
      var c = this.link.indexOf(" ");
      if (c !== -1) {
        this.link = this.link.substring(0, c)
      }
      var a = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z]{2,5}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g;
      if (this.link.length < 16 || !a.test(this.link)) {
        this.errorTip = "请输入正确的视频链接";
        return
      }
      this.errorTip = "";
      if (isMP4File(this.link)) {
        this.isMP4File = true;
        return
      }
      if (shortUrlArr.contains(parseHost(this.link))) {
        this.unShortUrlAndParseVideo();
        return
      }
      this.parseVideo()
    },
    unShortUrlAndParseVideo: function() {
      this.submitBtnClass.disabled = true;
      var b = this,
        c = Math.random().toString(10).substring(2),
        a = this.generateStr(this.link + "@" + c).toString(10);
      $.ajax({
        type: "POST",
        url: "http://service0.iiilab.com/url/unshort",
        xhrFields: {
          withCredentials: true
        },
        crossDomain: true,
        data: {
          link: b.link,
          r: c,
          s: a
        },
        dataType: "json",
        success: function(d) {
          if (d.succ) {
            b.link = d.data;
            b.parseVideo()
          } else {
            b.submitBtnClass.disabled = false;
            b.errorTip = d.retDesc
          }
        },
        error: function() {
          b.submitBtnClass.disabled = false;
          b.errorTip = "处理失败,请重试!"
        }
      })
    },
    parseVideo: function() {
      var d = parseHost(this.link);
      if (!hostMap.hasOwnProperty(d)) {
        d = parseSubHost(this.link)
      }
      if (hostMap.hasOwnProperty(d) && hostMap[d] != location.hostname) {
        this.redirect(hostMap[d]);
        return
      }
      if (typeof(ga) !== "undefined") {
        ga("send", "event", "analysis", "analysis-normal")
      }
      this.submitBtnClass.disabled = true;
      var b = this,
        c = Math.random().toString(10).substring(2),
        a = this.generateStr(this.link + "@" + c).toString(10);
      $.ajax({
        type: "POST",
        url: "http://service" + (service1Arr.contains(d) ? "3" : "0") + ".iiilab.com/video/web/" + site,
        xhrFields: {
          withCredentials: true
        },
        crossDomain: true,
        data: {
          link: b.link,
          r: c,
          s: a
        },
        dataType: "json",
        success: function(e) {
          b.submitBtnClass.disabled = false;
          if (e.succ) {
            b.requestResult = e.data;
            b.requestSuccess = true;
            b.cacheResult()
          } else {
            if (e.retCode == 300 && !b.linkFromInit) {
              b.redirect(location.hostname);
              return
            }
            b.errorTip = e.retDesc
          }
          b.linkFromInit = false
        },
        error: function(g, e, f) {
          b.submitBtnClass.disabled = false;
          if (isIE() && e === "error" && f.number === -2147024891) {
            b.errorTip = "由于您IE浏览器的安全设置，本站部分功能无法正常使用，请更改IE浏览器安全设置或更换为WebKit内核浏览器访问本站获得最佳上网体验。IE浏览器设置方法: 打开IE浏览器，依次选择右上角工具—Internet选项-安全-自定义级别-其它-通过域访问数据源，设置为启用即可。"
          } else {
            b.errorTip = "处理失败,请检查您的网络连接后重试!"
          }
        }
      })
    },
    init: function() {
      detectIE();
      var a = "?link=";
      if (location.search.indexOf(a) != -1 && location.search.substr(a.length) != "") {
        this.link = decodeURI(location.search.substr(a.length));
        history.replaceState("", "", "/");
        this.linkFromInit = true;
        this.submit();
        return
      }
      if (typeof(Storage) == "undefined") {
        return
      }
      if (localStorage.getItem("time") != null) {
        if (new Date().getTime() - localStorage.getItem("time") > 3600000) {
          this.removeLastResult();
          return
        }
      }
      if (localStorage.getItem("link") != null) {
        this.link = localStorage.getItem("link")
      }
      if (localStorage.getItem("requestResult") != null) {
        this.requestResult = localStorage.getObject("requestResult");
        this.requestSuccess = true
      }
    },
    initSponsor: function() {
      var a = this;
      $.ajax({
        type: "POST",
        url: "http://service0.iiilab.com/sponsor/getByPage",
        xhrFields: {
          withCredentials: true
        },
        crossDomain: true,
        data: {
          page: site
        },
        dataType: "json",
        success: function(b) {
          if (b.succ) {
            a.sponsor.text = b.data.text || [];
            a.sponsor.img = b.data.img || []
          } else {}
        },
        error: function() {},
        complete: function() {
          a.init();
          if (a.sponsor.img.length === 0) {
            $("#ga-code").html(a.gaCode)
          }
        }
      })
    },
    cacheResult: function() {
      if (typeof(Storage) == "undefined") {
        return
      }
      localStorage.setItem("time", new Date().getTime());
      localStorage.setItem("link", this.link);
      localStorage.setObject("requestResult", this.requestResult)
    },
    removeLastResult: function() {
      if (typeof(Storage) == "undefined") {
        return
      }
      this.isMP4File = false;
      this.requestSuccess = false;
      localStorage.removeItem("time");
      localStorage.removeItem("link");
      localStorage.removeItem("requestResult")
    },
    clear: function() {
      this.removeLastResult();
      this.link = "";
      ga("send", "event", "clear", "clear")
    },
    clearLinkInput: function() {
      this.removeLastResult();
      this.link = "";
      ga("send", "event", "clear", "clear-input")
    },
    redirect: function(a) {
      var b = location.protocol + "//" + a + "/?link=" + encodeURI(this.link);
      window.location.replace(b)
    },
    generateStr: function(a) {
      var c = function() {
          for (var d = 0, f = new Array(256), g = 0; 256 != g; ++g) {
            d = g, d = 1 & d ? -306674912 ^ d >>> 1 : d >>> 1, d = 1 & d ? -306674912 ^ d >>> 1 : d >>> 1, d = 1 & d ? -306674912 ^ d >>> 1 : d >>> 1, d = 1 & d ? -306674912 ^ d >>> 1 : d >>> 1, d = 1 & d ? -306674912 ^ d >>> 1 : d >>> 1, d = 1 & d ? -306674912 ^ d >>> 1 : d >>> 1, d = 1 & d ? -306674912 ^ d >>> 1 : d >>> 1, d = 1 & d ? -306674912 ^ d >>> 1 : d >>> 1, f[g] = d
          }
          return "undefined" != typeof Int32Array ? new Int32Array(f) : f
        }(),
        b = function(g) {
          for (var j, k, h = -1, f = 0, d = g.length; f < d;) {
            j = g.charCodeAt(f++), j < 128 ? h = h >>> 8 ^ c[255 & (h ^ j)] : j < 2048 ? (h = h >>> 8 ^ c[255 & (h ^ (192 | j >> 6 & 31))], h = h >>> 8 ^ c[255 & (h ^ (128 | 63 & j))]) : j >= 55296 && j < 57344 ? (j = (1023 & j) + 64, k = 1023 & g.charCodeAt(f++), h = h >>> 8 ^ c[255 & (h ^ (240 | j >> 8 & 7))], h = h >>> 8 ^ c[255 & (h ^ (128 | j >> 2 & 63))], h = h >>> 8 ^ c[255 & (h ^ (128 | k >> 6 & 15 | (3 & j) << 4))], h = h >>> 8 ^ c[255 & (h ^ (128 | 63 & k))]) : (h = h >>> 8 ^ c[255 & (h ^ (224 | j >> 12 & 15))], h = h >>> 8 ^ c[255 & (h ^ (128 | j >> 6 & 63))], h = h >>> 8 ^ c[255 & (h ^ (128 | 63 & j))])
          }
          return h ^ -1
        };
      return b(a) >>> 0
    }
  }
});
app.initSponsor();
$(document).ready(function() {
  $("#parent-nav").hover(function() {
    $("#child-nav").css("display", "block")
  }, function() {
    $("#child-nav").css("display", "none")
  })
});